package org.dydl.dao.system.repository;

import org.dydl.model.system.BusinessList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface IBusinessListRepository extends CrudRepository<BusinessList, Integer>,
		JpaSpecificationExecutor<BusinessList> {

	@Query(value = "FROM BusinessList bs ORDER BY bs.createTime DESC", countQuery = "SELECT count(bs.id) FROM BusinessList bs ORDER BY bs.createTime DESC")
	Page<BusinessList> getBusinessList(Pageable pageable);

	@Query(value = "FROM BusinessList bs WHERE bs.name LIKE :name ORDER BY bs.createTime DESC", countQuery = "SELECT count(bs.id) FROM BusinessList bs WHERE bs.name LIKE :name ORDER BY bs.createTime DESC" )
	Page<BusinessList> getBusinessListLike(@Param("name") String name,
			Pageable pageable);
//
//	@Modifying
//	@Transactional
//	@Query(value = "UPDATE orders set EXAMINE_STATUS = 1 WHERE ID = :id", nativeQuery = true)
//	void changeExamineStatus(@Param("id") int id);
//	
//	@Modifying
//	@Query(value = "UPDATE orders set PRODUCTION_INSTRUCTION_STATUS = 1,YD_GOODS_YIELD_STATUS = 1 WHERE ORDER_NO = :orderNo", nativeQuery = true)
//	void changeProductionInstructionStatus(@Param("orderNo") String orderNo);
//	
//	@Modifying
//	@Query(value = "UPDATE orders set DELIVERIES_STATUS = 1 WHERE ORDER_NO = :orderNo", nativeQuery = true)
//	void changeDeliveriesStatus(@Param("orderNo")String orderNo);
//	
	@Query(value = "SELECT * FROM businesshall WHERE id = :businessId", nativeQuery = true)
	BusinessList findBybusinessIds(@Param("businessId") String businessId);
	
	@Query(value = "SELECT name FROM businesshall WHERE id = :businessId", nativeQuery = true)
	String findNameByBusinessId(@Param("businessId") String businessId);
//
//	@Query(value = "SELECT UUID FROM orders WHERE ORDER_NO = :orderNo", nativeQuery = true)
//	String findUUIDByOrderNo(@Param("orderNo") String orderNo);
	

}
